﻿using System;
using DevExpress.Web.ASPxEditors;
using SaleManagement.Web.App_Code;
using SaleManagement.Services;
using SaleManagement.Web.Reports;
using SaleManagement.Domains;
using System.Data;

namespace SaleManagement.Web.Pages.Reports
{
  public partial class RGuarantee : BasePage
  {

    private int GuaranteeListId
    {
      get
      {
        int id = 0;
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
          int.TryParse(Request.QueryString["id"], out id);
        }
        return id;
      }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
      
      ShowReport();
    }

    private void ShowReport()
    {
      try
      {
        Domains.GuaranteeList guaranteeList = new GuaranteeListService().GetById(GuaranteeListId);
        if (guaranteeList == null) return;
        Customer customer = new CustomerService().GetById(guaranteeList.CustomerId.HasValue ? guaranteeList.CustomerId.Value : 0);
        if (customer == null) return;
        DataSet ds = new GuaranteeService().GetReportByListId(GuaranteeListId);

        rptGuarantee rpt = new rptGuarantee();
        rpt.prCustomerName.Value = customer.Name;
        rpt.prCustomerPhone.Value = customer.Phone;
        rpt.prCustomerAddress.Value = customer.Address;
        rpt.DataSource = ds;
        _rptViewerCtrl.Report = rpt;
      }
      catch (Exception ex)
      {
        WriteLog("RGuarantee.aspx:ShowReport", ex);
      }
    }
  }
}